package com.ruoyi.common.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
import java.util.HashSet;
/**
 * @author : manke
 * @Description
 * @Date: 2020/9/14 3:49
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //@Bean
    //public Docket createRestApi() {
    //    return new Docket(DocumentationType.SWAGGER_2)
    //            .apiInfo(apiInfo())
    //            .select()
    //            .apis(RequestHandlerSelectors.basePackage("com.xx.eurekaclient"))
    //            .paths(PathSelectors.any())
    //            .build();
    //}
    //private ApiInfo apiInfo() {
    //    return new ApiInfoBuilder()
    //            .title("springboot-getaway-consul-swagger")
    //            .description("springboot-getaway-consul-swagger----")
    //            .termsOfServiceUrl("111111")
    //            .version("1.0")
    //            .build();
    //}
    @Bean
    public Docket api() {
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("service-xx")
                .description("service-xx")
                .version("1.0.0")
                .build();
        HashSet<String> producesAndConsumes = new HashSet<>(Collections.singletonList("application/json"));
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ruoyi"))
                .paths(PathSelectors.any())
                .build()
                .produces(producesAndConsumes)
                .consumes(producesAndConsumes)
                .globalResponseMessage(org.springframework.web.bind.annotation.RequestMethod.GET, Collections.emptyList())
                .globalResponseMessage(RequestMethod.POST, Collections.emptyList())
                .globalOperationParameters(Collections.emptyList());
    }
}
